;
! function (window) {
  'use strict';

  // 用于初次进入页面就需要调用登录参数
  goToNativePage('getParams', 'getAssignParams')

  function getAssignParams(params) {
    var param;
    if (typeof params != 'string') {
      param = JSON.stringify(params)
    } else {
      param = params
    }
    sessionStorage.setItem('assignParams', param)
    param = JSON.parse(param || '{}')
    var uuid = param.uuid || '';
    if (!uuid) {
      //未登录
    } else {
      // 已登录
      getMoney(param)
    }
  }

  $('.bottom_img').click(function () {
    goToNativePage("tabBarSelected", "1")
  })

  // 获取当前用户的投资金额
  function getMoney(assignParams) {
    $.ajax({
      url: '/webp2p_interface_mysql/invest/investMIdAutumnActive/' + assignParams.customerUid + '/ACT_MIDAUTUMO_20180824',
      type: 'get',
      dataType: 'json',
      headers: {
        'accessToken': assignParams.accessToken,
        'deviceno': assignParams.deviceno,
        'version-code': assignParams['version_code'],
        'packageName': assignParams.packageName,
        'mobileOs': assignParams.mobileOs,
        "Content-Type": "application/json;charset=utf-8"
      },
      success: function (res) {
        if (res.result === '0000') {
          $('#content span').text(formatMoney(+res.data.allAmount / 100, 0))
        }
      },
      error: function (xhr) {
        showErrorToast(xhr, '');
      }
    })
  }

  /* 
   * formatMoney(s,type) 
   * 功能：金额按千位逗号分隔
   * 参数：s，需要格式化的金额数值. 
   * 参数：type,判断格式化后的金额是否需要小数位. 
   * 返回：返回格式化后的数值字符串. 
   */
  function formatMoney(s, type) {
    if (/[^0-9\.]/.test(s))
      return "0.00";
    if (s == null || s == "null" || s == "")
      return "0.00";
    s = s.toString().replace(/^(\d*)$/, "$1.");
    s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
    s = s.replace(".", ",");
    var re = /(\d)(\d{3},)/;
    while (re.test(s))
      s = s.replace(re, "$1,$2");
    s = s.replace(/,(\d\d)$/, ".$1");
    if (type == 0) {
      var a = s.split(".");
      if (a[1] == "00") {
        s = a[0];
      }
    }
    return s;
  }

  window.getAssignParams = getAssignParams;
}(window);